<template>
    <h2>房型管理添加</h2>
    <table class="table table-bordered">
        <tbody>
            <tr>
                <td>房间类型</td>
                <td>
                    <input type="text" v-model="form.name">
                </td>
            </tr>
            <tr>
                <td>房型</td>
                <td>
                    <select v-model="form.roomType">
                        <option>请选择</option>
                        <option>大床房</option>
                        <option>三人房</option>
                        <option>标准件</option>
                        <option>总统套房</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input type="radio" v-model="form.start" value="1">上架
                    <input type="radio" v-model="form.start" value="0">下架
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <button class="btn btn-primary" @click="Add">添加</button>
                </td>
            </tr>
        </tbody>
    </table>
</template>
<script setup lang="ts">
//引入组件
import { ref, reactive, onMounted } from "vue"
//bootstrap样式
import "bootstrap/dist/css/bootstrap.min.css"
//访问后端
import axios from "axios"
//路由(1)
import { useRouter } from "vue-router";

const router = useRouter();


const form = reactive({
    id: 0,
    name: "",
    roomType: "请选择",
    start: 0
})
const Add = () => {
    if (!form.name) {
        alert("名称不能为空！");
        return;
    }
    if (!form.roomType) {
        alert("房型不能为空！");
        return;
    }
    if (!form.start) {
        alert("状态不能为空！");
        return;
    }
    axios.post("http://localhost:5256/api/RoomHao/Add", form).then(res => {
        if (res.data > 0) {
            alert("添加成功！！");
            router.push("/roomHaoShow");
        }
        else {
            alert("添加失败！！");
        }
    })
}
</script>